package m.jclecai.com.adapter.klsfRecyclerAdapter;

import android.view.View;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import m.jclecai.com.R;
import m.jclecai.com.base.recyclerview.BaseRecyclerViewAdapter;
import m.jclecai.com.base.recyclerview.BaseViewHolder;
import m.jclecai.com.view.common.BallView;

/**
 * Created by andy on 2017/7/8.
 * 这里是快乐十分的小球的一个adapter;
 */
public class MyBallAdapter extends BaseRecyclerViewAdapter<String> {


    String[] missData = new String[0];
    public boolean isShowMissData=true;

    public Map<String,Boolean> mSelectBalls;

    public MyBallAdapter(List<String> DList) {
        super(DList);
        mSelectBalls =new HashMap<>();
    }

    @Override
    public int getItemView() {
        return R.layout.layout_item_ball;
    }

    @Override
    protected void bindViewHolder(BaseViewHolder holder, String bean, int position) {
        BallView ballView = holder.retrieveView(R.id.bv_ball_view);
        ballView.setNumber(bean);

        if (missData.length > position) {
            holder.getTextView(R.id.tv_missData).setText(missData[position]);
        } else {
            holder.getTextView(R.id.tv_missData).setText("-");
        }

        if (isShowMissData) {
            holder.getTextView(R.id.tv_missData).setVisibility(View.VISIBLE);
        }else{
            holder.getTextView(R.id.tv_missData).setVisibility(View.GONE);
        }

        ballView.setOnCheckedChangeListener(new BallView.OnCheckedChangeListener() {
            @Override
            public void onCheckedChange(BallView view, boolean isChecked) {
                mSelectBalls.put(view.getNumber(),isChecked);

                if (mOnBallCheckedListener != null) {
                    mOnBallCheckedListener.onBallChecked(view,isChecked);
                }
            }
        });
    }

    public Map<String,Boolean>  getSelectBalls(){
        return mSelectBalls;
    }

    public void setShowMissData(boolean isShowMissData){
        if (this.isShowMissData!=isShowMissData) {
            this.isShowMissData=isShowMissData;
            notifyDataSetChanged();
        }
    }

    public OnBallCheckedListener mOnBallCheckedListener;

    public void setOnBallCheckedListener(OnBallCheckedListener onBallCheckedListener) {
        mOnBallCheckedListener = onBallCheckedListener;
    }

    public interface OnBallCheckedListener{
         void onBallChecked(BallView view,Boolean isChecked);
    }

    public void refreshMissData(String[] missData){
        this.missData=missData;
        notifyDataSetChanged();
        mSelectBalls.clear();   //刷新数据的时候，我们是需要清空选中的条目；
    }
}
